class Solution:
    def permute(self, nums):
        len_nums, res = len(nums), []
        if len_nums <= 1:
            return nums
        elif len_nums == 2:
            return [[nums[0], nums[1]], [nums[1], nums[0]]]
        else:
            for i in nums:
                mid_list = nums[:]
                mid_list.remove(i)
                mid_res = self.permute(mid_list)
                for lists in mid_res:
                    lists.append(i)
                res.extend(mid_res)
        return res
                    

a = Solution()
print(a.permute([1, 2, 3]))
